package com.tracking.locon;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.Toast;

import com.google.android.maps.MapView;

public class Utility {
	
	/*
	 * Show a popup message
	 */
	public static void makeToast(Context context, String message) {
		Toast t = Toast.makeText(context, message, Toast.LENGTH_SHORT);
		t.show();
	}
	
	/*
	 * Convert meters to radius
	 */
	public static int metersToRadius(float meters, MapView map, double latitude) {
        return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
    }
	
	/*
	 * Scroll ListView to the bottom of the View
	 */
	public static void smoothScroll(final ListView listView){
		listView.post(new Runnable() { 
            public void run() { 
            	//listView.smoothScrollToPosition(view.getBottom());
            	listView.smoothScrollToPosition(listView.getCount() - 1);
            }
        });
	}
	
	/*
	 * Get the current time in HH:MM format
	 */
	public static String getTimeHHMM(long currentTimeInMillis){
		SimpleDateFormat formatter = new SimpleDateFormat("kk:mm");

	    Calendar calendar = Calendar.getInstance();
	    calendar.setTimeInMillis(currentTimeInMillis);
	    String timeHHMM = formatter.format(calendar.getTime());
		return timeHHMM;
	}
	
	/*
	 * Get the phone pixel width
	 */
	public static int getPhonePixelWidth(Context context){
		DisplayMetrics metrics = new DisplayMetrics();
		WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(metrics);
		return metrics.widthPixels;
	}
}
